from tkinter.font import names

text = "python编程很有趣"


print(text[0:6])
print(text[6:])
print(text[:6])
print(text[::2])
print(text[::-1])


phone = "13812345678"
print(f"运营商号段:{phone[:3]},尾号: {phone[-4]}")



csv_data ="苹果,香蕉,橙子,西瓜"
fruits = csv_data.split(",")
print(fruits)



log = "2023-08-20 14:30:25 [INFO] 用户登录成功"
parts = log.split(" ",2)
print(parts)



import re
text= "苹果;香蕉,橙子|西瓜"
print(re.split(r"[;,]|\|",text))




words= ["Hello","word","!"]
print(" ".join(words))



path_parts = ["C:,""User","Alice","file.txt"]
print("\\".join(path_parts))


conditions = ["age >18","gender = 'H'", "status = 1"]
sql = "SELECT * FROM users WHERE" + " AND ".join(conditions)
print(sql)




user_input = "   some text   "
print(f"|{user_input.strip()}|")



code = ">>>print('hello')<<<"
print(code.strip("><"))



dirty_data =",,value1,value2,value3,,"
clean_data = [x.strip() for x in dirty_data.split(",") if x.strip()]
print(clean_data)





name = "Alice"
age = 25
score= 95.5678




print(f"{name}今年{age}岁")



print(f"分数: {score:.1f}")
print(f"十六进制: {age:#x}")
print(f"百分比: {0.25:.2%}")


print(f"姓名: {name:<10}")
print(f"年龄: {age:^10}")
print(f"分数: {score:>10.2f}")


print(f"明年年龄: {age + 1}")



print(f"大写名字: {name.upper()}")


user = {"name": "Bob", " age": 30}
print(f"用户: {user['name']},年龄: {user['age']}")








log_line = "2023-08-20 14:30:25 [ERROR] 文件未找到: /path/to/file"

date = log_line[:10]
time = log_line[11:19]
level,message = log_line[21:].split(")",1)
print(f"""\
解析结果:
日期: {date}
时间: {level[1:]}
信息: {message}\
""")

data =[
    ["Python","3.10","2021"],
    ["Java","17","2021"],
    ["C++","20","2020"]
]


col_widths = [
    max(len(item) for item in col)
    for col in zip(*data)
]


header = ["语言","版本","发布年"]
divider = "+".join(["-" * (w + 2) for w in col_widths])
print(divider)
for row in data:
    print(f"|{' | '.join(item.ljust(w) for item ,w in zip(row, col_widths))} |")
